package com_.dxy_test_.diy_tomcat_;

import lombok.Data;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * @Description 自定义请求类
 * @Author dangxianyue
 * @Date 2022/9/26 14:41
 */
@Data
public class MyRequest {

    //HTTP协议报文格式如下（主要是读取第一行）：
    //GET /user/findById?id=1000 HTTP/1.1
    //Host: 127.0.0.1:8080
    //Connection: keep-alive
    //Upgrade-Insecure-Requests: 1
    //User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.116 Safari/537.36
    //Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
    //Sec-Fetch-Site: none
    //Sec-Fetch-Mode: navigate
    //Sec-Fetch-User: ?1
    //Sec-Fetch-Dest: document
    //Accept-Encoding: gzip, deflate, br
    //Accept-Language: zh-CN,zh;q=0.9
    //Cookie: siteId=2c254a3dfd344686922a027f2aead8df1; siteCode=xxzj

    /**
     * 请求url
     */
    private String url;

    /**
     * 请求方法
     */
    private String method;

    public MyRequest(InputStream inputStream) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));
        //读取第一行，即请求行
        String requestLine = reader.readLine();
        System.out.println("requestLine: " + requestLine);
        String[] lines = requestLine.split(" ");
        this.method = lines[0];
        this.url = lines[1];

    }


}
